package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.business.dao.inter.FamilyEvaluationNurseStaffDao;
import com.yunfeisoft.business.model.Elder;
import com.yunfeisoft.business.model.FamilyEvaluationNurseStaff;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * ClassName: FamilyEvaluationNurseStaffDaoImpl
 * Description: 长者家属对护理员评价表Dao实现
 * Author: Jackie liu
 * Date: 2020-05-22
 */
@Repository
public class FamilyEvaluationNurseStaffDaoImpl extends BaseDaoImpl<FamilyEvaluationNurseStaff, String> implements FamilyEvaluationNurseStaffDao {

    @Override
    public Page<FamilyEvaluationNurseStaff> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        wb.setOrderByWithDesc("createTime");
        if (params != null) {
            initPageParam(wb, params);
            if (!ObjectUtils.isEmpty(params.get("elderName"))) {
                wb.andFullLike("e.name", params.get("elderName"));
            }
        }
        SelectBuilder builder = getSelectBuilder("f");
        builder.column("e.name as elderName")
                .join(Elder.class).alias("e")
                .on("e.id = f.elderId").build();
        return queryPage(builder.getSql(), wb);
    }
}